package com.wjk.kylin.mall.auth.feign.fallback;

import com.wjk.kylin.mall.auth.feign.MemberFeignService;
import com.wjk.kylin.mall.common.core.bo.member.MemberUserNameBO;
import com.wjk.kylin.mall.common.core.dto.base.DataOutDTO;
import com.wjk.kylin.mall.common.core.dto.member.MemberUserNameInDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Service;

/**
 * 调用方熔断保护 Factory
 * 可以打印异常等处理
 */
@Slf4j
@Service
public class MemberFeignServiceFallbackFactory implements FallbackFactory<MemberFeignService> {

    @Override
    public MemberFeignService create(Throwable throwable) {
        return new MemberFeignService() {
            @Override
            public DataOutDTO<MemberUserNameBO> loadUserByUsername(MemberUserNameInDTO inDTO) {
                log.error("loadUserByUsername 熔断异常：{}", throwable.getMessage());
                return null;
            }
        };
    }
}
